#include "AISeek.h"
#include "Timer.h"
#include "Game.h"
#include "Agent.h"

#include "D3DXVECTOROperators.h"
//#include <D3DX10.h>

void AISeek::Update()
{	
	// calc steering force
	D3DXVECTOR3 vec = m_target->GetPosition() - m_agent->GetPosition();
	
	// test if arrived at target
	float rad = D3DXVec3Length(&vec);

	// calc seek
	m_agent->AddForce(vec);
	

	//if ((D3DXVec3LengthSq(&m_agent->GetForce())) > m_agent->GetMaxForce())
	//{
	//	D3DXVec3Normalize(&m_agent->GetForce(), &m_agent->GetForce());
	//	m_agent->GetForce() *= m_agent->GetMaxForce();
	//}

	//// calc acceleration
	//D3DXVECTOR3 acceleration = m_agent->GetForce() * (1.0f / m_agent->GetMass()); // inverse mass

	//// calc velocity
	//D3DXVECTOR3 oldVel = m_agent->GetVel();
	//m_agent->GetVel() += acceleration * TheTimer::Instance()->GetDt();
	//
	//// clamp velocity
	//if (D3DXVec3LengthSq(&m_agent->GetVel()) > D3DXVec3LengthSq(&m_agent->GetMaxVel()))
	//{
	//	D3DXVec3Normalize(&m_agent->GetVel(), &m_agent->GetVel());
	//	D3DXVec3Mult(&m_agent->GetVel(), m_agent->GetMaxVel());
	//}

	//// update position
	//m_agent->GetPosition() += (oldVel + m_agent->GetVel()) * 0.5f * TheTimer::Instance()->GetDt();

	//TheGame::Instance()->GetMaze()->CheckCollision(m_agent->GetPosition(), 3.0f);

	//// update heading and side vectors
	//D3DXVec3Normalize(&m_agent->GetHeading(), &m_agent->GetVel());
	//m_agent->GetHeading().z = -m_agent->GetHeading().z;
	//m_agent->GetSide() = m_agent->GetHeading();
}